Repository navigation
fix(browser): Instrument empty-URL XHR and show the page URL in breadcrumbs - #26201
Conversation
s1gr1d
left a comment
There was a problem hiding this comment.
Thanks, the XHR fix looks good!
Regarding your "Unsure about": let's keep it to empty URLs
| function getBreadcrumbUrl(url: string): string { | ||
| const pageurl = url === '' ? WINDOW.location?.href : undefined; | ||
| return filterCollectedUrl(pageurl ? stripUrlQueryAndFragment(pageurl) : url); | ||
| } |
There was a problem hiding this comment.
filterCollectedUrl already filters sensitive params (e.g. token=[Filtered]) based on dataCollection.urlQueryParams.
We could only drop the fragment and let filterCollectedUrl handle the rest.
| function getBreadcrumbUrl(url: string): string { | |
| const pageurl = url === '' ? WINDOW.location?.href : undefined; | |
| return filterCollectedUrl(pageurl ? stripUrlQueryAndFragment(pageurl) : url); | |
| } | |
| function getBreadcrumbUrl(url: string): string { | |
| const pageurl = url === '' ? WINDOW.location?.href : undefined; | |
| return filterCollectedUrl(pageUrl ? pageUrl.split('#')[0]! : url, client); | |
| } |
There was a problem hiding this comment.
Some test nits:
- consider using
toHaveBeenCalledWithinstead ofmock.calls restoreAllMocksinstead ofresetAllMocks, and unset the client after each test
6206414 to
149a4b3
Compare
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Want reviews to match your repository better? Bugbot Learning can learn team-specific rules from PR activity. A team admin can enable Learning in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 149a4b3. Configure here.
Head branch was pushed to by a user without write access
|
your bugbot scares me off @s1gr1d |
This PR adds the external contributor to the CHANGELOG.md file, so that they are credited for their contribution. See #26201 Co-authored-by: s1gr1d <32902192+s1gr1d@users.noreply.github.com>

Why:
fetch('')is instrumented, butxhr.open('GET', '')was not, and once an empty URL request is instrumented its breadcrumb showsurl: "". This PR fixes bothxhr.tsbailed on!url, which treats an empty string like an unparseable argument, so empty-URL XHRs got no breadcrumb and no span. It now only bails onurl === undefined, so XHR matches fetch."". Query and fragment are stripped withstripUrlQueryAndFragment, so params like?token=from the page URL don't end up in breadcrumbs. Since an empty URL resolves to the page URL itself, the helper useslocation.hrefdirectly instead of callingnew URL()(bcoz its throws for hrefs likeabout:srcdoc). without alocationobject (e.g. workers), nothing changes.Only empty URLs are rewritten, absolute and relative URLs keep their current breadcrumb behaviour.
How to review:
Start with:
packages/browser-utils/src/instrumentation/xhr.tspackages/browser/src/integrations/breadcrumbs.tsand the regression coverage in:
packages/browser-utils/test/instrumentation/xhr.test.tspackages/browser/test/integrations/breadcrumbs.test.tsThe key things to check are that only empty URLs are rewritten, and that the query and fragment are stripped from the page URL in all three breadcrumb paths (fetch, failed fetch, XHR).
Unsure about:
Whether relative URLs (like
/api/foo?x=1) should also be resolved againstlocation.hrefand stripped in breadcrumbs. I kept this limited to empty URLs so the change stays scoped, but yeah I'm happy to widen it.Ref #13168